interface UserInfo {
  username?: string;
  userage?: number;
  usersex?: string;
}

interface UserState {
  userInfo: Nullable<UserInfo>;
  token?: string;
}

export const useUserStore = defineStore({
  id: "app-user",
  state: (): UserState => ({
    userInfo: null,
    token: undefined
  }),
  getters: {
    getUserInfo(): UserInfo {
      return this.userInfo || {};
    },
    getToken(): string {
      return this.token || "";
    }
  },
  actions: {
    setUserInfo(info: UserInfo | null) {
      this.userInfo = info;
    },
    setToken(info: string | undefined) {
      this.token = info ? info : "";
    },
    resetState() {
      this.userInfo = null;
      this.token = "";
    }
  }
});
